﻿using AiXiu.BLL;
using AiXiu.Common;
using AiXiu.IBLL;
using AiXiu.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AiXiu.WebStite
{
    public partial class Mobile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string mobile = txtMobileNumber.Text;
                string password = txtPassword.Text;
                IMobileManger accountManger = new MobileManger();
                OperResult<TBUsers> operResult = accountManger.LoginByUserName(mobile, password);
                if (operResult.StatusCode == StatusCode.Succeed)
                {
                    TBUsers users = operResult.ReadResult();
                    IdentityManager.SaveUser(users);

                    string redirectUrl = Request.QueryString["ReturnUrl"];
                    if (string.IsNullOrWhiteSpace(redirectUrl))
                    {
                        redirectUrl = "Default.aspx";
                    }
                    this.AlertAndRedirect("Lgnsuccess","登陆成功", redirectUrl);
                }
                else
                {
                    this.Alert("lgnfail", operResult.Message ?? "登录失败！！");
                }

            }
        }
    }
}